<?php include(VIEWSPATH.'/common/header.php') ?>
<?php include(VIEWSPATH.'/common/header.php') ?>
<script type="text/javascript" src="<?php echo base_url('/assets/js/framework/ajaxfileupload.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/js/framework/jquery-format-num.js'); ?>"></script>

<script>
	$(document).ready(function() {
		$(".warning-numeric").format({autofix:true},function(){alert("Not an number");});
		$("#btn_create").click(function(){
			if (validate_update_product("create") == false )
			{
				return ;
			}
			$.post("<?php echo base_url("/product/create")?>",
			{
				type : $("#type").val(),
				material : $("#material").val(),				
				price: $("#txt_price").val()+"000",
				note :$("#txt_note").val(),
				image:$("#hdf_image_path").val()
			},
			function(data){
				alert("Đã tạo thông tin thành công ");
				window.location ="<?php echo base_url('/product/view/')?>"+data.id;
			},"json");
		}); 
	});
</script>
<style>
	table td{
		text-align:left;
	}
</style>
<div id="err_list"></div>
<table  align="center">
	<tr>
		<td width="100">Loai</td>
		<td>
			<select id="type">
				<option id="1" value ="1" >truyen thong </option>
				<option id="2" value ="2">cach tan </option>
			</select>
		</td>
	</tr>
	<tr>
		<td width="100">Chat Lieu</td>
		<td>
			<select id="material">
				<?php foreach( $materials as $key => $value) {?>
					<option id="<?php echo $key ?>" value ="<?php echo $key ?>" > <?php echo $value?></option>
				<?php }?>
			</select>
		</td>
	</tr>
	<tr>
		<td width="100" >Gia tien </td>
		<td>
			<input type="text" id ="txt_price" style="width :100px;" value="" maxlength="7" class="warning-numeric"> Ngàn/VNĐ
		</td>
	</tr>
	<tr>
		<td width="100">Ghi chu </td>
		<td>
			<textarea type="text" id ="txt_note" rows="3"></textarea>
		</td>
	</tr>
	<tr>
		<td width="100">Hinh anh </td>
		<td>
			<input type="file" name ="picture" id="picture"></input><input type="button" id="btn_upload" onclick="ajaxFileUpload('picture','show_img','hdf_image_path','<?php echo base_url('/common/upload_image'); ?>')" value="upload"></input>
			<div >
				 <img id="show_img" ></img>
			</div>
			<input type="hidden" id="hdf_image_path"></input>
		</td>
	</tr>
	<tr >
		<td colspan="2" style="text-align:center">	
			<input type="submit" name="btn_create" id="btn_create" value="Thêm"></input>
		</td>
	</tr>
</table>

<?php include(VIEWSPATH.'/common/footer.php') ?>